package bma.common.netty.protobuf.sample;

import bma.common.langutil.core.ObjectUtil;
import bma.common.netty.protobuf.core.PServiceMethod;
import bma.common.netty.protobuf.core.impl.PServiceBase;
import bma.common.netty.protobuf.sample.SampleProtos.Sample_error_args;
import bma.common.netty.protobuf.sample.SampleProtos.Sample_name_args;
import bma.common.netty.protobuf.sample.SampleProtos.Sample_name_result;
import bma.common.netty.protobuf.sample.SampleProtos.Sample_say_args;
import bma.common.netty.protobuf.sample.SampleProtos.Sample_sleep_args;

public class SamplePService extends PServiceBase {

	final org.slf4j.Logger log = org.slf4j.LoggerFactory
			.getLogger(SamplePService.class);

	@PServiceMethod
	public void say(Sample_say_args args) {
		log.info("hello " + args.getWord());
	}

	@PServiceMethod
	public Sample_name_result name(Sample_name_args args) {
		String r = "hello " + args.getTitle();
		return Sample_name_result.newBuilder().setResult(r).build();
	}

	@PServiceMethod
	public void error(Sample_error_args args) {
		throw new IllegalArgumentException("ERROR:" + args.getMessage());
	}

	@PServiceMethod
	public void sleep(Sample_sleep_args args) {
		if (args.getTime() > 0) {
			ObjectUtil.waitFor(this, args.getTime());
		}
	}
}
